package com.ljt.yupictureddd.infrastracture.exception;

/**
 * 异常处理工具类
 */
public class ThrowUtils {
    /**
     * 最普通的抛出异常
     * @param condition
     * @param exception
     */
    public static void throwIf(boolean condition, RuntimeException exception){
        if (condition){
            throw exception;
        }
    }

    /**
     * 有errorCode了抛出业务异常
     * @param condition
     * @param errorCode
     */
    public static void throwIf(boolean condition, ErrorCode errorCode) {
        throwIf(condition, new BusinessException(errorCode));
    }

    /**
     * 继续封装成一个更自定义的抛业务异常，最常用
     * @param condition
     * @param errorCode
     * @param errorMessage
     */
    public static void throwIf(boolean condition,ErrorCode errorCode,String errorMessage){
        throwIf(condition,new BusinessException(errorCode,errorMessage));
    }

}
